package com.itheima.demo04;

public class SelectionDemo02 {
    public static void main(String[] args) {
        //选择排序
        //规则： 是拿0索引上的值跟后面的值一一比较，如果前面的值比后面的值大就交接位置

        //1.定义数据
        int[] arr = {2, 4, 5, 3, 1};
        //第一轮比较
       /* for (int i = 0 + 1; i < arr.length; i++) {
            System.out.println(arr[0] + " "+ ","+arr[i] + " ");
            if (arr[0] > arr[i]){
                int temp = arr[0];
                arr[0] = arr[i];
                arr[i] = temp;
            }
        }*/
        //最終代碼
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }


        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

    }
}
